package com.controller.backend;

import com.biz.SysConfigBiz;
import com.core.Result;
import com.core.ResultGenerator;
import com.entity.model.SysConfig;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.util.Base64;
import com.wechat.mina.ComponentUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by jc on 2020/03/16.
 */
@Controller
@RequestMapping("/backend/security/sysConfig")
public class SysConfigController extends BaseController<SysConfig> {
    @Autowired
    private SysConfigBiz sysConfigBiz;

    @RequestMapping(value = "index")
    public String index() throws Exception {
        return "/backend/security/sysConfig/list";
    }

    @RequestMapping(value = "getMinaQr")
    @ResponseBody
    public Result getMinaQr(String str,String page) throws Exception {
        String qrUrl = null;
        String scene = Base64.encode(str.getBytes("UTF-8"));
        try {
            /*page = "pages/my/settleIn/index";*/
            qrUrl = ComponentUtil.getMinaQr("{\"scene\":\"" + scene + "\",\"page\":\"" + page + "\"}", page + scene);
        } catch (WeixinException e) {
            e.printStackTrace();
        }

        if (StringUtils.isNotBlank(qrUrl)) {
            return ResultGenerator.genSuccessResult(qrUrl);
        } else {
            return ResultGenerator.genFailResult("获取小程序二维码失败，请稍后重试");
        }
    }
}
